package com.wxapp.system.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.system.api.pojo.vm.city.PCityDetailVm;
import com.wxapp.system.api.pojo.vm.city.PCityPageVm;
import com.wxapp.system.api.pojo.vm.city.PCityRelationTreeVm;
import com.wxapp.system.api.pojo.vm.city.PCityRelationVm;
import com.wxapp.system.api.pojo.vo.city.QCitySaveVo;
import com.wxapp.system.api.pojo.vo.city.QCitySearchVo;
import com.wxapp.system.api.pojo.vo.city.QCityUpdateVo;
import com.wxapp.system.service.service.CityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 省市县查询工具类
 * @Datetime 2022/11/10 11:06
 * @Modified By
 */
@RestController
@RequestMapping("city")
@Tag(name = "省市县")
@RequiredArgsConstructor
public class CityController extends IBaseController {

    private final CityService cityService;

    @PostMapping("/save")
    @Operation(summary ="保存省市县信息")
    public ResultVm<String> save(@Schema(hidden = true) @User UserVo userVo, @RequestBody QCitySaveVo qSaveVo) {
        return cityService.save(userVo, qSaveVo);
    }

    @PutMapping("/update")
    @Operation(summary ="更新省市县信息")
    public ResultVm<String> update(@Schema(hidden = true) @User UserVo userVo, @RequestBody QCityUpdateVo qSaveVo) {
        return cityService.update(userVo, qSaveVo);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary ="得到省市县详情")
    public ResultVm<PCityDetailVm> detail(@PathVariable String id) {
        return cityService.detail(id);
    }


    @DeleteMapping("/delete/{id}")
    @Operation(summary ="删除省市县")
    public ResultVm<String> delete(@PathVariable String id) {
        return cityService.delete(id);
    }


    @PostMapping("page")
    @Operation(summary ="获取省市县树形菜单")
    public ResultVm<Page<PCityPageVm>> getPage(@RequestBody QCitySearchVo qCitySearchVo) {
        return cityService.getPage(qCitySearchVo);
    }

    @GetMapping("relation")
    @Operation(summary ="获取联动省市县树形菜单")
    public ResultVm<List<PCityRelationVm>> relation(@RequestParam(value = "pid", required = false) String pid) {
        return cityService.relation(pid);
    }

    @PostMapping("relationTree")
    @Operation(summary ="获取联动省市县树形菜单")
    public ResultVm<List<PCityRelationTreeVm>> relationTree(@RequestBody QCitySearchVo qCitySearchVo) {
        return cityService.relationTree(qCitySearchVo);
    }
}
